package com.cartoon.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cartoon.bean.Cartoon;
import com.cartoon.service.CartService;
import com.cartoon.service.impl.CarServiceImpl;

@WebServlet("/index.do")
public class IndexServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req,resp);
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		CartService cs = new CarServiceImpl();
		List<Cartoon> list = cs.selectByselling(2);
		List<Cartoon> list4 = cs.selectBysex("女");
		List<Cartoon> list5 = cs.selectBysex("男");
		
		List list2 = new ArrayList();
		List list3 = new ArrayList();
		List list6 = new ArrayList();
		for(int i=0 ; i<5 ;  i++){
			int a = (int)(Math.random()*(list.size()));
			list2.add(list.get(a));
		}
		for(int i=0 ; i<6 ;  i++){
			int a = (int)(Math.random()*(list4.size()));
			list3.add(list4.get(a));
		}
		for(int i=0 ; i<6 ;  i++){
			int a = (int)(Math.random()*(list5.size()));
			list6.add(list5.get(a));
		}
		List<Cartoon> list7 = cs.selectByqyue(2);
		List list8 = new ArrayList();
		for(int i=0 ; i<8 ;  i++){
			int a = (int)(Math.random()*(list7.size()));
			list8.add(list7.get(a));
		}
		List<Cartoon> list9 = cs.selectBypiao();
		
		req.setAttribute("list", list2);
		req.setAttribute("list2", list3);
		req.setAttribute("list3", list6);
		req.setAttribute("list4", list8);
		req.setAttribute("list5", list9);
		req.getRequestDispatcher("index.jsp").forward(req, resp);
	}

}
